8 // define a simple reverb.
12 5.do({ in = AllpassN.ar(in, 0.05, [0.05.rand, 0.05.rand], 2); });
19 // define 100 randomly generated percussive FM instruments.
20 // this will take a few seconds.
21 // this code can be modified to generate sustaining instruments.
22 var carrierF, middleF, modulatorF;
25 carrierF = { arg freq=440, mod=0, mix=0, gate=1;
27 //e = Env.adsr(exprand(0.001,maxAttack), linrand(3.0), rrand(0.4,1.0).squared, rrand(0.001,0.2));
28 e = Env.perc(exprand(0.001,maxAttack), exprand(0.1,2.0));
30 e = EnvGen.kr(e, gate, rrand(0.5,0.6).rand.squared);
31 SinOsc.ar(freq * m, mod, e, mix);
34 middleF = { arg freq=440, mod=0, mix=0, gate=1;
36 //e = Env.adsr(exprand(0.001,maxAttack), linrand(3.0), 1.0.rand.squared, rrand(0.001,0.2));
37 e = Env.perc(exprand(0.001,maxAttack), exprand(0.1,2.0));
39 e = EnvGen.kr(e, gate, 3.0.rand.squared);
40 SinOsc.ar(freq * m, mod, e, mix);
43 modulatorF = { arg freq=440, mix=0, gate=1;
45 //e = Env.adsr(exprand(0.001,maxAttack), linrand(3.0), 1.0.rand.squared, rrand(0.001,0.2));
46 e = Env.perc(exprand(0.001,maxAttack), exprand(0.1,2.0));
48 e = EnvGen.kr(e, gate, 3.0.rand.squared);
49 SinOsc.ar(freq * m, 1.3.rand.cubed, e, mix);
54 name = "fmgen_a_" ++ i;
55 SynthDef(name, { arg freq=440, amp=1, gate=1, pan=0;
61 // sum of 3 modulator->carrier pairs
65 f = freq + 1.8.rand2.squared;
66 m = modulatorF.(f, 0, gate);
67 c = carrierF.(f, m, c, gate);
71 // sum of 2 modulator->modulator->carrier chains
75 f = freq + 1.8.rand2.squared;
76 m = modulatorF.(f, 0, gate);
77 m = middleF.(f, m, 0, gate);
78 c = carrierF.(f, m, c, gate);
82 // sum of 2 modulator-+->carrier
88 f = freq + 1.8.rand2.squared;
89 m = modulatorF.(f, 0, gate);
90 c = carrierF.(f, m, c, gate);
91 c = carrierF.(f, m, c, gate);
96 DetectSilence.ar(c, doneAction: 2);
97 Out.ar(0, Pan2.ar(c, pan, amp));
104 // listen randomly to the random FM instruments.
107 s.sendMsg(\s_new, \reverb, 1000, 1, 0);
108 name = "fmgen_a_" ++ 100.rand;
112 if (0.08.coin) { name = "fmgen_a_" ++ 100.rand; name.postln };
113 [1,1,1,1,1,2,2].choose.do {
114 freq = rrand(24,84).midicps;
115 id = 1000000000.rand;
116 s.sendMsg(\s_new, name, id, 0, 0, \freq, freq, \amp, 0.4, \pan, 1.0.rand2);
118 [0.1, 0.1, 0.1, 0.2, 0.2, 0.4, 0.8, 1.6].choose.wait;
120 s.sendMsg(\n_free, 1000);